local yunyong = fk.CreateSkill{
  name = "hanqing__yunyong",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__yunyong"] = "云涌",
  [":hanqing__yunyong"] = "锁定技，每轮开始时，或当一名有“狂风”标记的角色受到伤害后，你令一名没有“狂风”标记的角色获得“狂风”标记。",

  ["#hanqing__yunyong-choose"] = "云涌：请选择一名角色获得“狂风”标记",

  ["$hanqing__yunyong1"] = "万骑云会，八阵戎装，我武维扬！",
  ["$hanqing__yunyong2"] = "云蒸雾郁，转石走沙，飞泰山之形。",
}

local spec = {
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return p:getMark("@@kuangfeng") == 0
    end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = yunyong.name,
      prompt = "#hanqing__yunyong-choose",
      cancelable = false,
    })[1]
    room:addPlayerMark(to, "@@kuangfeng", 1)
    room:addSkill("aux_kuangfeng")
  end,
}

yunyong:addEffect(fk.RoundStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yunyong.name) and
      table.find(player.room.alive_players, function (p)
        return p:getMark("@@kuangfeng") == 0
      end)
  end,
  on_use = spec.on_use,
})

yunyong:addEffect(fk.Damaged, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yunyong.name) and
      (data.extra_data or {}).hanqing__yunyong and
      table.find(player.room.alive_players, function (p)
        return p:getMark("@@kuangfeng") == 0
      end)
  end,
  on_use = spec.on_use,
})

yunyong:addEffect(fk.BeforeHpChanged, {
  can_refresh = function(self, event, target, player, data)
    return data.damageEvent and player == data.damageEvent.to and player:getMark("@@kuangfeng") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.damageEvent.extra_data = data.damageEvent.extra_data or {}
    data.damageEvent.extra_data.hanqing__yunyong = true
  end,
})

return yunyong
